def twoSum(nums, target):
    table = {nums[i]: i for i in range(len(nums))}
    for i in range(len(nums)):
        if target - nums[i] in table and table[target - nums[i]] != i:
            return [i, table[target - nums[i]]]
    return []


nums = [3, 2, 4]
target = 6
print(twoSum(nums, target))  # [1, 2]
